package servidorBanco;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import clienteTeste.Mensageiro;

public class Gestor extends UnicastRemoteObject implements Mensageiro {

	private Connection conn;
	
	protected Gestor() throws RemoteException {
		super();
		this.conn = new ConnectionFactory().getConnection();
		if (conn != null){
			System.out.println("criei conexao");
		}else{
			System.out.println("bd nao levanta");
		}
		// TODO Auto-generated constructor stub
	}


	private static final long serialVersionUID = 1L;

	@Override
	public String hello(String nome) throws RemoteException {
		return "Vai trabalhar" + nome;
	}

	@Override
	public String comunica(String comando) throws RemoteException {
		System.out.println("entrando no comunica");
		String 	sql = comando;
		// PreparedStatement pstm = new PreparedstatementFactory().getPreparedStatement(conn, sql);
		
		//ResultSet rs = pstm.executeQuery();
		try {
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return comando;
	}
	
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return super.toString();
	}

}
